<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div id="app">
      <p>{{txt}}</p>
      <button @click="add">反转</button>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        //定义属性
        data: {
          txt: "Hello,World",
        },
        //定义方法
        methods: {
          /*
            思路:
            1.单词拆分成一个字符数组
            2.reverse方法对字符数组进行反转操作，将字符的顺序颠倒过来
            3.join将反转后的字符数组重新连接成一个字符串
            */
          add() {
            this.txt = this.txt.split("").reverse().join("");
          },
        },
      });
    </script>
  </body>
</html>
